﻿using System;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Common;
using DevExpress.Web;

namespace Web.Pages.YongShui._4.ChaoBiaoKZ
{
    public partial class HuiZongCWXX : BasePage
    {
        #region 属性
        public DataTable MyDataTable
        {
            get { return ViewState["MyDataTable"] != null ? ViewState["MyDataTable"] as DataTable : null; }
            set { ViewState["MyDataTable"] = value; }
        }

        #endregion

        #region 变量
        /// <summary>
        /// 数据库
        /// </summary>
        SpHelper _spHelper = new SpHelper();
        #endregion

        #region 事件


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                BindHUIZONG();

            }
            gvWenJianGZ.DataSource = MyDataTable;
            gvWenJianGZ.DataBind();
        }

        /// <summary>
        /// 下拉选项变动调用事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DrpQK_SelectedValueChanged(object sender, EventArgs e)
        {



            BindHUIZONG();

        }

        #endregion

        #region  方法
        /// <summary>
        /// 初始化控件  并绑定值
        /// </summary>
        private void InitControl()
        {
            string yd = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            IYIM.Text = $"{yd.Substring(0, 4)}年{yd.Substring(4, 2)}月";
            txtYear.Text = yd.Substring(0, 4);
            txtMonth.Text = yd.Substring(4, 2);
            gvWenJianGZ.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //获取当前用户站点信息
            string zhandianBH = BusinessTool.ZHANDIANBH();

            YS_JX_GUANLIKBLL glkbll = new YS_JX_GUANLIKBLL();

            DataTable glkdt = glkbll.SelectYS_JX_GUANLIKsDynamic(" I_JLZT=0 and (S_ZHANDIAN='" + zhandianBH + "' or '00'='" + zhandianBH + "')", " S_GUANLIKH");

            DrpQK.DataSource = glkdt;
            DrpQK.TextField = "S_GUANLIKMC";
            DrpQK.ValueField = "S_GUANLIKH";
            DrpQK.DataBind();

            if (zhandianBH == "00")
            {
                DrpQK.Items.Insert(0, new DevExpress.Web.ListEditItem("所有区块", "0"));

            }
            //DrpQK.Items.Insert(0, new DevExpress.Web.ListEditItem("  ", "-1"));
            DrpQK.SelectedIndex = 0;


        }
        /// <summary>
        /// 显示错误
        /// </summary>
        private void BindHUIZONG()
        {



            YS_CB_HUIZONGCWBLL hzxxbll = new YS_CB_HUIZONGCWBLL();
            DataTable dtI_GUANBIAO = WordsHelper.GetXiaoLeiListByWordsID(10);
            int StartMonth = 0;
            int EndMnth = 0;
            if (dtI_GUANBIAO != null && dtI_GUANBIAO.Rows.Count > 0)
            {
                foreach (DataRow dr in dtI_GUANBIAO.Rows)
                {
                    if (dr["WordsContent"].ToString().Trim() == "冬灌表起始月")
                    {
                        StartMonth = Convert.ToInt32(dr["WordsValue"]);
                    }
                    if (dr["WordsContent"].ToString().Trim() == "冬灌表中止月")
                    {
                        EndMnth = Convert.ToInt32(dr["WordsValue"]);
                    }
                }
            }
            string SGUANLIKH = "";
            SGUANLIKH = DrpQK.Value.ToString();


            int syear = 0;
            int smonth = 0;
            string yd = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            if (yd != null && yd.Trim().Length == 6)
            {
                syear = Convert.ToInt32(yd.Substring(0, 4));
                smonth = Convert.ToInt32(yd.Substring(4, 2));
            }
            int? errcode = 0;
            DataSet ds = _spHelper.P_YS_CB_HUIZONGCW(SGUANLIKH, syear, smonth, StartMonth, EndMnth, 1, out errcode);
            DataTable dt = ds.Tables[0];
            MyDataTable = dt;
            gvWenJianGZ.DataSource = MyDataTable;
            gvWenJianGZ.DataBind();
            LabNum.Text = dt == null ? "合计:0 笔" : "合计:" + dt.Rows.Count + " 笔";

        }



        #endregion
    }
}